package two;

import java.util.Random;
import java.util.Scanner;

public class MonsterGame {

    static class Player {
        int hp;
        int attack;
        int defense;  // 防御力
        int intelligence;  // 智力
        int stamina;  // 体力
        int dodge;  // 躲避

        Player(int hp, int attack, int defense, int intelligence, int stamina, int dodge) {
            this.hp = hp;
            this.attack = attack;
            this.defense = defense;
            this.intelligence = intelligence;
            this.stamina = stamina;
            this.dodge = dodge;
        }
    }

    static class Monster {
        int hp;
        int attack;
        int defense;  // 防御力
        int intelligence;  // 智力
        int stamina;  // 体力
        int dodge;  // 躲避
        String name;

        Monster(int hp, int attack, int defense, int intelligence, int stamina, int dodge, String name) {
            this.hp = hp;
            this.attack = attack;
            this.defense = defense;
            this.intelligence = intelligence;
            this.stamina = stamina;
            this.dodge = dodge;
            this.name = name;
        }
    }

    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        Random random = new Random();
        // 创建玩家
        Player player = new Player(100, 15, 5, 10, 20, 10);  // 设置玩家属性

        while (player.hp > 0) { // 当玩家还有生命值时，继续战斗
            // 创建怪物
            Monster monster = null;
            int monsterType = random.nextInt(3);  // 随机选择怪物类型
            switch (monsterType) {
                case 0: monster = new Monster(50, 10, 3, 5, 15, 5, "史莱姆"); break;
                case 1: monster = new Monster(70, 15, 7, 8, 20, 10, "哥布林"); break;
                case 2: monster = new Monster(100, 20, 10, 5, 25, 15, "狼人"); break;
            }
            System.out.println("你遇到了一个 " + monster.name + "！");

            while (player.hp > 0 && monster.hp > 0) {
                // 玩家回合
                System.out.println("你的 HP：" + player.hp + "，" + monster.name + " 的 HP：" + monster.hp);
                System.out.println("请选择你的行动：1. 攻击 2. 使用技能 3. 使用道具");
                int choice = scanner.nextInt();

                if (choice == 1) {
                    // 玩家攻击
                    if (random.nextInt(100) < monster.dodge) {
                        System.out.println(monster.name + " 躲避了你的攻击！");
                    } else {
                        int damage = player.attack - monster.defense;
                        if (damage > 0) {
                            monster.hp -= damage;
                            System.out.println("你攻击了 " + monster.name + "，造成了 " + damage + " 点伤害！");
                        } else {
                            System.out.println("你的攻击被 " + monster.name + " 防御住了！");
                        }
                    }
                } else if (choice == 2) {
                    // 玩家使用技能
                    System.out.println("请选择你的技能：1. 治疗 2. 魔法攻击");
                    int skillChoice = scanner.nextInt();
                    if (skillChoice == 1) {
                        // 治疗
                        player.hp += 10;
                        System.out.println("你使用了治疗技能，恢复了 10 点生命值！");
                    } else if (skillChoice == 2) {
                        // 魔法攻击
                        if (random.nextInt(100) < monster.dodge) {
                            System.out.println(monster.name + " 躲避了你的魔法攻击！");
                        } else {
                            int damage = player.intelligence;  // 智力影响魔法伤害
                            monster.hp -= damage;
                            System.out.println("你使用了魔法攻击，造成了 " + damage + " 点伤害！");
                        }
                    } else {
                        System.out.println("无效的技能选择！");
                    }
                } else if (choice == 3) {
                    // 玩家使用道具
                    System.out.println("请选择你的道具：1. 治疗药水 2. 攻击药水");
                    int itemChoice = scanner.nextInt();
                    if (itemChoice == 1) {
                        // 治疗药水
                        player.hp += 20;
                        System.out.println("你使用了治疗药水，恢复了 20 点生命值！");
                    } else if (itemChoice == 2) {
                        // 攻击药水
                        player.attack += 5;
                        System.out.println("你使用了攻击药水，提升了 5 点攻击力！");
                    } else {
                        System.out.println("无效的道具选择！");
                    }
                } else {
                    System.out.println("无效的选项！");
                }

                // 怪物回合
                if (monster.hp > 0) {
                    // 躲避判定
                    if (random.nextInt(100) < player.dodge) {
                        System.out.println("你躲避了 " + monster.name + " 的攻击！");
                    } else {
                        int damage = monster.attack - player.defense;
                        if (damage > 0) {
                            player.hp -= damage;
                            System.out.println(monster.name + " 攻击了你，造成了 " + damage + " 点伤害！");
                        } else {
                            System.out.println(monster.name + " 的攻击被你防御住了！");
                        }
                    }
                }
            }
            if (monster.hp <= 0) {
                System.out.println("你战胜了 " + monster.name + "！ ");
            } else {
                System.out.println("你被 " + monster.name + " 打败了！");
            }
        }
        System.out.println("游戏结束！");
        scanner.close();
    }
}